<?php
/**
 * @author 后台用户系统
 */
namespace backend\service\system;


use bc\service\base\Service;
use backend\models\system\MenuModel;

class MenuService extends Service
{
	public function __construct()
	{
		$this->model = new MenuModel();
	}
	
	
	public function getMenuList()
	{
		$params = ['status' => 1, 'is_menu' => 1];
		$this->sort = 'id ASC';
		$list = $this->getList($params);
		$resutl =  $this->recursion($list, 0);
		return $resutl;
	}
	
	
	public function getAllList($params)
	{
		$this->sort = 'id ASC';
		$list = $this->getList($params);
		$resutl =  $this->recursion($list, 0);
		return $resutl;
	}
	
	/**
	 * 递归数据
	 * @param array $data
	 */
	private function recursion($data, $root)
	{
		$tree = '';
		foreach ( $data as $k => $v )
		{
			if ($v ['parent_id'] == $root)
			{
				// 父亲找到儿子
				$v ['child'] = $this->recursion ( $data, $v ['id'] );
				$tree [] = $v;
				unset($data[$k]);
			}
		}
		return $tree;
	}
}